import * as echarts from "echarts";

function opt(doc, x, data, ymax, col, ti, barW, type,optionObj3) {

	let op2 = { //柱状折线图
		tooltip: {
			trigger: 'axis',
			axisPointer: {
				type: 'cross',
				crossStyle: {
					color: '#fff'
				}
			}
		},
		toolbox: {
			feature: {
				dataView: {
					show: false,
					readOnly: false
				},
				magicType: {
					show: false,
					type: ['line', 'bar']
				},
				restore: {
					show: false //还原
				},
				saveAsImage: {
					show: false //保存图片
				}
			}
		},
		legend: {
			data: ['预算金额', '预算执行率', '%'],
			textStyle: {
				color: 'rgb(255,255,255,0.9)'
			}
		},
		xAxis: [{
			type: 'category',
			data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
			axisPointer: {
				type: 'shadow'
			},
			splitLine: {
				show: false
			},
			axisLabel: {
				color: '#fff'
			},
		}],
		yAxis: [{
				type: 'value',
				name: '预算执行率',
				min: 0,
				max: 100,
				interval: 25,
				axisLabel: {
					formatter: '{value} w'
				},
				splitLine: {
					show: false
				},
				axisLabel: {
					color: '#fff'
				},
			},
			{
				type: 'value',
				name: '%',
				min: 0,
				max: 100,
				interval: 25,
				axisLabel: {
					formatter: '{value} %'
				},
				splitLine: {
					show: false
				}
			}
		],
		series: [{
				name: '预算金额',
				type: 'bar',
				tooltip: {
					valueFormatter: function(value) {
						return value + ' w';
					}
				},
				data: [
					12, 14, 20, 3, 6, 17
				]
			},
			{
				name: '预算执行率',
				type: 'bar',
				tooltip: {
					valueFormatter: function(value) {
						return value + ' w';
					}
				},
				data: [
					81, 10, 62, 20, 30, 9
				]
			},
			{
				name: '%',
				type: 'line',
				yAxisIndex: 1,
				tooltip: {
					valueFormatter: function(value) {
						return value + ' %';
					}
				},
				data: [56, 90, 30, 12, 40, 11]
			}
		]
	};


	//柱状图
	let dataShadow = [];
	for (let i = 0; i < data.length; i++) {
		dataShadow.push(ymax);
	}
	let op1 = {
		title: {
			subtext: ti,
			subTextStyle: {
				color: '#fff'
			}
		},
		xAxis: {
			data: x,
			axisLabel: {
				color: '#fff'
			},
			splitLine: {
				show: false
			},
			axisTick: {
				show: false
			},
			axisLine: {
				show: false
			},
			z: 10
		},
		yAxis: {
			axisLine: {
				show: false
			},
			splitLine: {
				show: false
			},
			axisTick: {
				show: false
			},
			axisLabel: {
				color: '#fff'
			}
		},
		dataZoom: [{
			type: 'inside'
		}],
		series: [{
			type: 'bar',
			showBackground: true,
			barWidth: barW,
			itemStyle: {
				color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
						offset: 0,
						color: col[0]
					},
					{
						offset: 0.5,
						color: col[1]
					},
					{
						offset: 1,
						color: col[2]
					}
				])
			},
			emphasis: {
				itemStyle: {
					color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
							offset: 0,
							color: col[0]
						},
						{
							offset: 0.7,
							color: col[1]
						},
						{
							offset: 1,
							color: col[2]
						}
					])
				}
			},
			data: data
		}]
	};

	let op3 = {
		series: [{
				type: 'gauge',
				center: ['50%', '60%'],
				startAngle: 200,
				endAngle: -20,
				min: 0,
				max: 100,
				splitNumber: 5,
				itemStyle: {
					color: optionObj3.co2
				},
				progress: {
					show: true,
					width: 30
				},
				pointer: {
					show: false
				},
				axisLine: {
					lineStyle: {
						width: 30
					}
				},
				axisTick: {
					distance: -45,
					splitNumber: 5,
					lineStyle: {
						width: 2,
						color: '#999'
					}
				},
				splitLine: {
					distance: -52,
					length: 14,
					lineStyle: {
						width: 3,
						color: '#999'
					}
				},
				axisLabel: {
					distance: -20,
					color: '#999',
					fontSize: 20
				},
				anchor: {
					show: false
				},
				title: {
					show: false
				},
				detail: {
					valueAnimation: true,
					width: '60%',
					lineHeight: 40,
					borderRadius: 8,
					offsetCenter: [0, '-15%'],
					fontSize: 60,
					fontWeight: 'bolder',
					formatter: '{value} °C',
					color: 'auto'
				},
				data: [{
					value: optionObj3.value1
				}]
			},
			{
				type: 'gauge',
				center: ['50%', '60%'],
				startAngle: 200,
				endAngle: -20,
				min: 0,
				max: optionObj3.max,
				itemStyle: {
					color: optionObj3.co1
				},
				progress: {
					show: true,
					width: 8
				},
				pointer: {
					show: false
				},
				axisLine: {
					show: false
				},
				axisTick: {
					show: false
				},
				splitLine: {
					show: false
				},
				axisLabel: {
					show: false
				},
				detail: {
					show: false
				},
				data: [{
					value: optionObj3.value2
				}]
			}
		]
	};
	let mye = echarts.init(doc)


	


	switch (type) {
		case 0: //柱状图
			mye.setOption(op1)
			break;
		case 1:
			mye.setOption(op2)
			break;
		case 3:
			mye.setOption(op3)
			break;
		default:
			mye.setOption(op1)
			break;
	}


}
export default opt;
